//
//  ToolItemCell.swift
//  Tools
//
//  Created by Mac on 2021/4/15.
//

import UIKit

class ActionItemCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        layer.cornerRadius = 10
        clipsToBounds = true
        contentView.addSubview(colorBgView)
        colorBgView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        colorBgView.addSubview(iconImageView)
        iconImageView.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview().offset(10)
            make.size.equalTo(CGSize(width: 40, height: 40))
        }
        colorBgView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.iconImageView.snp.bottom).offset(10)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
        }
    }
    
    lazy var colorBgView : UIView = {
        let colorBgView = UIView(frame: .zero)
        return colorBgView
    }()
    
    lazy var iconImageView : UIImageView = {
        let iconImageView = UIImageView(frame: .zero)
        iconImageView.tintColor = .white
        iconImageView.contentMode = .scaleAspectFill
        iconImageView.clipsToBounds = true
        iconImageView.layer.cornerRadius = 10
        return iconImageView
    }()
    
    lazy var nameLabel : UILabel = {
        let nameLabel = UILabel(frame: .zero)
        nameLabel.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        nameLabel.font = .systemFont(ofSize: 17, weight: .medium)
        nameLabel.numberOfLines = 0
        return nameLabel
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var _model : ActionModel!
    public var model : ActionModel!{
        set{
            _model = newValue
            //设置数据
            colorBgView.backgroundColor = .systemGray
            nameLabel.text = newValue.name
            iconImageView.image = UIImage(named: newValue.icon)
        }
        get{
            return _model
        }
    }
}
